<%@page import="hyl.core.MyFun"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%><%@ include file="pub/top.jsp"%>
<%@ page import="java.util.List,java.util.Map"%>
<%
String ualias = "";
if(request.getParameter("ualias")!=null&&!request.getParameter("ualias").isEmpty()){
	ualias=request.getParameter("ualias");
}
String start = "";
if(request.getParameter("start")!=null&&!request.getParameter("start").isEmpty()){
	start=request.getParameter("start");
}
String end = "";
if(request.getParameter("end")!=null&&!request.getParameter("end").isEmpty()){
	end=request.getParameter("end");
}
%>
<!-- 全局变量 函数定义区 -->
<%!%>
<!-- 实例变量 函数定义区 -->
<%
	//网页title
	String JSPTITLE = "用户管理";
%>
<%@ include file="pub/head.jsp"%>
<!-- 样式添加区 -->
<link rel="stylesheet" href="<%=basePath%>DataTables/datatables.min.css">
<!-- 下右内容区 -->

<div id="my-modal" class="modal fade" tabindex="-1">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h3 class="smaller lighter blue no-margin">绑定设备</h3>
			</div>
			<input type="text" id="hide" style="display:none">
			<div class="modal-body">
				<span><i style="color:red">*</i>设备编号</span><br>
				<input type="text" id="imei" class="form-control">
			</div>
			<div class="modal-footer">
			<button onclick="bind()">提交</button>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal-dialog -->
</div>

<div class="main-content-inner">
	<div class="breadcrumbs ace-save-state" id="breadcrumbs">
		<ul class="breadcrumb">
			<li><i class="ace-icon fa fa-home home-icon"></i>用户管理</li>
			<li class="active"><%=JSPTITLE%></li>
		</ul>
	</div>
	<div class="page-content">
		<!-- page-header{ -->
		<div class="page-header">
			<!-- table header1{ -->
			<div class="row">
				<div class="col-xs-12">
					<div class="clearfix">
						<div class="pull-right tableTools-container"></div>
						<div class="">
							<div class="btn-group" style="margin-top: 5px">
								<a href="#" class="btn-refresh btn  btn-xs "> <i
									class="im-spinner10 fa-spin"></i> 刷新
								</a>
								<a data-toggle="collapse" href="#demo" class=" btn  btn-xs ">
									<i class="im-spinner10 fa-spin"></i>搜索
								</a>
							</div>
						</div>
					</div>
					<div id="demo" class="panel-collapse collapse ">
						<div class="panel-body well">
							<form>
								<div class="col-lg-12 col-sm-12  input-group ">
									<span class="input-group-addon">
						          		<i class="fa fa-calendar"></i>
						         	</span>
							        <input type="date" name="start" value="<%=start %>">
							        &nbsp&nbsp
							        <span>至</span>
							        &nbsp&nbsp
							        <input type="date" name="end" value="<%=end %>"> 
									&nbsp&nbsp
									<input type="text" name="ualias" value="<%=ualias %>" 
										placeholder="会员姓名" >									
						        </div>
								<div class="col-lg-12 col-sm-12">
									<button type="submit"
										class="btn btn-success btn-sm  pull-right">
										<span class="ace-icon fa fa-search icon-on-right bigger-110"></span>
										查找
									</button>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
			<!-- }table -header1  -->
		</div>
		<!-- }page-header  -->

		<!-- table header2{ -->
		<div class="row">
			<div class="col-xs-9 tablehead2L"></div>
			<div class="col-xs-3 tablehead2R"></div>
		</div>
		<!-- }table -header2  -->
		<!--  table { -->
		<div class="row tablexscroll" >	
				<table id="myTable" class="table table-striped table-bordered"
					cellspacing="0" >
					<thead>
						<tr>
						</tr>
					</thead>
					<tbody>
					</tbody>
				</table>
		
		</div>
		<!--}table  -->
		<!-- table end{ -->
		<div class="row">
			<div class="col-xs-4"></div>
			<div class="col-xs-8">
				<ul class="pagination"></ul>
				<span class="tablefooterinfo"></span>
			</div>
		</div>
		<!--}table end -->
	</div>
</div>
<!--  footer{ -->
<div class="footer">
	<div class="footer-inner">
		<div class="footer-content  pull_right">
			<span class="bigger-110"> <span class="blue bolder"></span>
			</span>
		</div>
	</div>
</div>
<!--}  footer -->

<a href="#" id="btn-scroll-up"
	class="btn-scroll-up btn btn-sm btn-inverse"> <i
	class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
</a>

<%@ include file="pub/bottom.jsp"%>
<!-- 引入组件库 -->
<script src="<%=basePath%>DataTables/datatables.min.js"></script>
<script src="<%=basePath%>js/hyl.page.js"></script>
<!-- 自定义脚本 加载区 -->
<script>
function detail(id,roleid){
	var url = BASEPATH+"admin/member_student.jsp?id="+id+"&role="+roleid;
	window.location.href=url;
}

function bind(){
	var id = $('#hide').val();
	var imei = $('#imei').val();
	if(imei==null||imei==""){
		alert("设备号不能为空");
		return;
	}
	$.ajax({
		type : 'get',
		url : '<%=basePath%>admin/Dao/device_bind.jsp',
		data : {"id":id,"imei":imei,"state":2},
		success : function(data) {
			var code = data.replace(/\s+/g,"");
			if(code=="error"){
				alert("请确认IMEI是否正确");
				flag=0;
				return;
			}else{
				alert("绑定成功!");
				window.location.reload();
			}
		}
	});
}

function jbind(id){
	$.ajax({
		type : 'get',
		url : '<%=basePath%>admin/Dao/device_bind.jsp',
		data : {"id":id,"state":1},
		success : function(data) {
			var code = data.replace(/\s+/g,"");
			alert("解绑成功!");
			window.location.reload();
		}
	});
}

function show(id){
	$('#hide').val(id);
	$('#my-modal').modal('show');
}

var BASEPATH="<%=basePath%>";
  $(document).ready(function() {
    var table = $('#myTable').DataTable({
      dom : '',
      renderer : "bootstrap",
      paging : false,
      "ordering" : false,
      "searching" : false,
      "info" : false,
      buttons : [
          'colvis', 'pdf', {
            text : 'My button',
            action : function(dt) {
              console.log('My custom button!');
            }
          }
      ],
      //stateSave: true, 
 	  "language" : {
        "lengthMenu" : "每页 _MENU_ 条记录",
        "zeroRecords" : "没有找到记录",
        "info" : "第 _PAGE_ 页 ( 总共 _PAGES_ 页 )",
        "infoEmpty" : "无记录",
        "infoFiltered" : "(从 _MAX_ 条记录过滤)"
      //, "decimal": ".", "thousands": "," ,
      },	 
      //列属性声明
      
      //render特定列

//  a.uid,b.uname,b.ualias, a.l0,a.l8
      "columnDefs" : [ 
        {   title : "编号",
          "render" : function(data, type, row) {
            return  row[0] ;
          },
          "targets" : 0
        },{
            title : "登录帐号",
            "render" : function(data, type, row) {
              return row[1];
            },
            "targets" : 1
        },{
            title : "姓名",
            "render" : function(data, type, row) {
              return row[2];
            },
            "targets" : 2
        },{
            title : "注册时间",
            "render" : function(data, type, row) {
              return row[4]==null?"":fmtTime(row[4]);
            },
            "targets" : 3
        },{
            title : "状态",
            "render" : function(data, type, row) {
            	var tt= '<span class="user-status status-online"></span>有效';
            	if(row[8]!=row[9]){
            		tt= '<span class="user-status status-busy"></span>无效';
            	}
              return tt;
            },
            "targets" : 4
        },{
            title : "操作",
            "render" : function(data, type, row) {
            	var button="";
            	
            	/* button+='<button class="btn btn-sm btn-success btn-white btn-round " onclick="show('+row[0]+')">绑定</button>'; */
                
            return button;
            },
            "targets" : 5
        } 
        
        ],
      "footerCallback" : function(row, data, start, end, display) {
        //汇总统计回调函数
        
      }
    });
    
    //自定义的分页的函数,名字不要改 确保与page.js中的调用函数名一致;
    //载入数据的函数
    //传入第几页
    var PG = HylPage.getInstance("<%=JSPTITLE%>");
    PG.load = function(n) {
      var  pgindex= PG.sessionPgIndex();//缓存成上一次定位的页
      if (pgindex&&(!n))
        n=pgindex;
      else if((!pgindex)&&(!n)){
        n=1;
      }
      //需要传到后台的参数 	
      var data1 = {
        "rs_index" : (n - 1) * PG.pgSize,//从第几条记录开始
        "rs_size" : PG.getMaxRcNum(),//取几条数据过来
        "ualias" : $("input[name='ualias']").val(),
        "start" : $("input[name='start']").val(),
        "end" : $("input[name='end']").val()
      };
      //用法: $.post("chargelist2.do", data1).success(function(rs) {});    	
      //解释: (去哪里,要做什么) 成功做完成以后{
      // 返回以后 做什么...
      //}
      $.post("<%=basePath%>admin/Dao/member_sdao.jsp", data1).success(function(result) {
				//console.log(result);
			PG.bind({
				tableobj : table,
				pageobj : $(".pagination"),
				rs : result.BODY._rs,
				pindex : n,
				psize : 0,
				totalnum: result.BODY.total
			});
			if (result.BODY.total&& result.BODY.total > 0)
					$(".tablefooterinfo").html("一共查询到"+ result.BODY.total+ "条记录");});
			}
			PG.load();
						//行点击事件
						$('#myTable tbody').on('click', '.btn-del', function() {
							var qtr = $(this).parent('tr');
							var data = table.row(qtr.get(0)).data();
							//alert('You clicked on ' + data[0] + '\'s row');
						});
						$('#myTable tbody').on('click', '.btn-chg', function() {
							var qtr = $(this).parent('tr');
							var data = table.row(qtr.get(0)).data();
							//alert('You clicked on ' + data[0] + '\'s row');
						});
					});
</script>
